<?php
	add_action('widgets_init', 'register_comingsoon_deals_wg');
	function register_comingsoon_deals_wg()
	{
		register_widget('coming_soon_deals');
	}

	class coming_soon_deals extends WP_Widget // widget class
	{
		function coming_soon_deals()// widget setting | class name must be same function name
		{ 
			$widget_ops = array('classname' => 'coming-soon-deals-w', 'description' => 'Display coming soon deals (right side bar)');
			$control_ops = array(
				'width' => 250,
				'height' => 350,
				'id_base' => 'coming_soon_deals');
			$this->WP_Widget('coming_soon_deals', 'DealX - Coming soon deals', $widget_ops, $control_ops);
		}

	function widget($args, $instance)// display widget
	{
        global $post;
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        
        $number_show = $instance['number_show'];
        if(!$number_show)
            $number_show = 5;
        $cms_deals = cpx_get_comingsoon_deals();
        if(count($cms_deals) > 0)
        { ?>
        <div class="right-sibar-wrap">
            <div class="right-sidebar-title">
                <span><?php echo $title; ?></span>
                <div class="clr"></div>
            </div>
            <div class="all-deals-list row-fluid">
            <?php
            foreach ($cms_deals as $p) 
            {
                cpx_get_deal_info($p->ID, 1, 1, '', 1);
            }
            ?>
            </div>
        </div>
        <?php
        }
	}
	function update($new_instance, $old_instance)// update widget
	{
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        $instance['number_show'] = $new_instance['number_show'];
        return $instance;
	}

	function form($instance)
	{
	   ?>
         <div style="color: #333;">
    		<p>        
    			<label for="<?php echo $this->get_field_id('title');?>"><?php echo 'Title'; ?></label>
    			<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php	echo $this->get_field_name('title');?>" value="<?php echo $instance['title'];?>" style="width:100%;" />
    		</p>
            <p>
    			<label for="<?php echo $this->get_field_id('number_show');?>"><?php echo 'Number to show';?>
    			<input type="text" id="<?php echo $this->get_field_id('number_show');?>" name="<?php echo $this->get_field_name('number_show');?>" value="<?php echo $instance['number_show'];?>" style="width:15%;" />
                stores (default 5)</label>
    		</p>
        </div>
    <?php
	}
}
?>
